package org.example.physics_engine.geometry.shapes;

import lombok.Getter;
import lombok.Setter;
import org.example.physics_engine.body.Mass;
import org.example.physics_engine.body.Transform;
import org.example.physics_engine.geometry.*;

//四分之一圆
@Getter
@Setter
public class QuarterCircle extends AbstractShape{

    //四分之一圆的半径
    protected double radius;

    //顶点数组
    protected Vector2d[] vertices;

    public QuarterCircle(Transform transform, double radius) {
        super(transform);
        this.radius = radius;
        this.vertices = new Vector2d[3];
        this.vertices[0] = new Vector2d(-radius / 2, radius / 2);
        this.vertices[1] = new Vector2d(-radius / 2, -radius / 2);
        this.vertices[2] = new Vector2d(radius / 2, -radius / 2);
    }

    public QuarterCircle(double radius) {
        this(new Transform(), radius);
    }

    //反序列化调用
    //单位圆
    @Deprecated
    public QuarterCircle() {
        this(1);
    }

    @Override
    public void zoom(int rate) {
        if (rate < 1) return;
        this.radius = this.radius / this.rate * rate;
        int size = vertices.length;
        for (int i = 0; i < size; i++) {
            vertices[i] = vertices[i].multiplyNum((double) rate / this.rate);
        }
        this.rate = rate;
    }

    @Override
    public AxisAlignBoundingBox createAABB() {
        return new Rectangle(this.radius / 2, this.radius / 2, this.transform.copy()).createAABB();
    }

    @Override
    public Interval project(Vector2d axis) {
        //用不到
        return null;
    }

    @Override
    public Mass createMass(double density) {
        double r2 = this.radius * this.radius;
        double mass = density * Math.PI * r2 / 4;
        double inertia = mass * r2 * 0.5;
        return new Mass(new Vector2d(4 * Math.sqrt(2) * radius / 3 / Math.PI - radius / 2,
                4 * Math.sqrt(2) * radius / 3 / Math.PI - radius / 2), mass, inertia);
    }

    @Override
    public Vector2d[] getFocus() {
        //用不到
        return null;
    }

    @Override
    public Vector2d[] getAxes(Vector2d[] focus) {
        //用不到
        return null;
    }

    @Override
    public Vector2d getFarthestFeature(Vector2d vector) {
        //用不到
        return null;
    }

    @Override
    public Vector2d getFarthestPoint(Vector2d vector) {
        //用不到
        return null;
    }
}
